package com.hd.util;


import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author hzhh123
 * @time 2018年4月19日下午2:47:58
 **/
public class CollectionUtil<T> {

    /**
     * 求差集
     * @param aList
     * @param bList
     * @return
     */
    public List<T> differenceSet(List<T> aList, List<T> bList) {
        List<T> cList = new ArrayList<T>();
        cList.addAll(aList);
        cList.removeAll(bList);
        return  cList;
    }

    /**
     * 交集
     * @param aList
     * @param bList
     * @return
     */
    public List<T> intersectionSet(List<T> aList, List<T> bList) {
        List<T> cList = new ArrayList<T>();
        cList.addAll(aList);
        cList.retainAll(bList);
        return  cList;
    }

    /**
     * 并集
     * @param aList
     * @param bList
     * @return
     */
    public List<T> union(List<T> aList, List<T> bList) {
        List<T> cList = new ArrayList<T>();
        cList.addAll(aList);
        cList.addAll(bList);
        return  cList;
    }

    /**
     * 去重并集
     * @param aList
     * @param bList
     * @return
     */
    public List<T> union2(List<T> aList, List<T> bList) {
        List<T> cList = new ArrayList<T>();
        cList.addAll(aList);
        cList.removeAll(bList);
        cList.addAll(bList);
        return  cList;
    }

    public static void main(String[] args){
        CollectionUtil<String>collectionUtil=new CollectionUtil<String>();
        List<String> aList= Arrays.asList("a","b");
        List<String> bList= Arrays.asList("a","b","c");
        System.out.println(collectionUtil.differenceSet(aList,bList));
        System.out.println(collectionUtil.differenceSet(bList,aList));
        System.out.println(collectionUtil.intersectionSet(bList,aList));
        System.out.println(collectionUtil.union2(aList,bList));
    }
}

